<?php
namespace app\index\model;
use app\common\model\Base;

class Username extends Base
{
    //插入新用户
    public function setNewUser($tjrid=0,$dml=0,$reg_user,$reg_pass,$agent,$je=0,$ntime,$login_ip,$position='',$us_class=1,$beizhu='',$fdian,$fukuduan,$login_key,$dl=0,$tjm='',$isok=0) {
        $res = Username::name('username')
                ->bind(['tjrid'=>$tjrid,'dml'=>$dml,'username'=>$reg_user,'password'=>$reg_pass,'tjr'=>$agent,'je'=>$je,'reg_time'=>$ntime,'reg_ip'=>$login_ip,'position'=>$position,'us_class'=>$us_class,'beizhu'=>$beizhu,'fandian'=>$fdian,'khd'=>$fukuduan,'login_key'=>$login_key,'dl'=>$dl,'tjm'=>$tjm,'isok'=>$isok])
                ->insert(['tjrid'=>':tjrid','dml'=>':dml','username'=>':username','password'=>':password','tjr'=>':tjr','je'=>':je','reg_time'=>':reg_time','reg_ip'=>':reg_ip','position'=>':position','us_class'=>':us_class','beizhu'=>':beizhu','fandian'=>':fandian','khd'=>':khd','login_key'=>':login_key','dl'=>':dl','tjm'=>':tjm','isok'=>':isok']);
        return $res;
    }
    //修改密码
    public function updatePass($username,$password) {
        $res = Username::name('username')
                ->bind(['username'=>$username,'password'=>$password])
                ->where('username',':username')
                ->update(['password'=>':password']);
        return $res;
    }
    //修改提现密码
    public function updatePassEjmm($username,$ejmm) {
    	$res = Username::name('username')
    	->bind(['username'=>$username,'ejmm'=>$ejmm])
    	->where('username',':username')
    	->update(['ejmm'=>':ejmm']);
    	return $res;
    }
    //修改返点
    public function updateFandian($id,$fandian) {
        $res = Username::name('username')
        ->bind(['id'=>$id,'fandian'=>$fandian])
        ->where('id',':id')
        ->update(['fandian'=>':fandian']);
        return $res;
    }
    //修改下线返点
    public function updateSubFandian($id,$fandian) {
        $res = Username::name('username')
        ->bind(['id'=>$id,'xxfandian'=>$fandian])
        ->where('id',':id')
        ->update(['xxfandian'=>':xxfandian']);
        return $res;
    }
    //插入试玩账号信息
    public function setTryPlayUser($username,$password,$je,$fandian,$beizhu,$reg_time,$reg_ip,$position='',$us_class,$swzh,$login_key,$open,$from) {
        $res = Username::name('username')
                ->bind(['username'=>$username,'password'=>$password,'ejmm'=>$password,'je'=>$je,'fandian'=>$fandian,'beizhu'=>$beizhu,'reg_time'=>$reg_time,'reg_ip'=>$reg_ip,'position'=>$position,'us_class'=>$us_class,'swzh'=>$swzh,'login_key'=>$login_key,'open'=>$open,'khd'=>$from])
                ->insert(['username'=>':username','password'=>':password','ejmm'=>':ejmm','je'=>':je','fandian'=>':fandian','beizhu'=>':beizhu','reg_time'=>':reg_time','reg_ip'=>':reg_ip','position'=>':position','us_class'=>':us_class','swzh'=>':swzh','login_key'=>':login_key','open'=>':open','khd'=>':khd']);
        return $res;
    }
    //更新用户登录信息
    public function updateLoginInfo($id,$login_key,$login_time,$usclass,$login_ip='') {
        $res = Username::name('username')
        ->bind(['id'=>$id,'login_key'=>$login_key,'login_time'=>$login_time,'login_ip'=>$login_ip,'us_class'=>$usclass])
        ->where('id',':id')
        ->update(['login_key'=>':login_key','login_time'=>':login_time','login_ip'=>':login_ip','us_class'=>':us_class']);
        return $res;
    }
    //更新用户投注信息
    public function updateUserBetInfo($je,$dml,$tzzje,$username,$zyh_tzzje) {
        $res = Username::name('username')
        ->bind(['je'=>$je,'dml'=>$dml,'tzzje'=>$tzzje,'username'=>$username,'zyh_tzzje'=>$zyh_tzzje])
    	->where('username',':username')
    	->update(['je'=>':je','dml'=>':dml','tzzje'=>':tzzje','zyh_tzzje'=>':zyh_tzzje']);
        return $res;
    }
    //线上充值后更新用户信息
    public function upUserXsczInfo($je,$dml,$czzje,$username) {
        $res = Username::name('username')
        ->bind(['je'=>$je,'dml'=>$dml,'czzje'=>$czzje,'username'=>$username])
        ->where('username',':username')
        ->update(['je'=>':je','dml'=>':dml','czzje'=>':czzje']);
        return $res;
    }
    //更新用户金额信息
    public function updateMoneyInfo($username,$amount,$type) {
        if($type == 'up') {
            //增加金额
            $res = Username::name('username')
            ->bind(['username'=>$username])
            ->where('username',':username')
            ->setInc('je',$amount);
            return $res;
        } else if($type == 'down') {
            //减少金额
            $res = Username::name('username')
            ->bind(['username'=>$username])
            ->where('username',':username')
            ->setDec('je',$amount);
            return $res;
        }
    }
    //更新用户打码量信息
    public function updateDmlInfo($username,$dml,$type) {
        if($type == 'up') {
            //增加打码量
            $res = Username::name('username')
            ->bind(['username'=>$username])
            ->where('username',':username')
            ->setInc('dml',$dml);
            return $res;
        } else if($type == 'down') {
            //减少打码量
            $res = Username::name('username')
            ->bind(['username'=>$username])
            ->where('username',':username')
            ->setDec('dml',$dml);
            return $res;
        }
    }
    //绑定用户银行信息
    public function bindBankInfo($username,$account_holder,$account_bank,$account_number,$province,$city,$mobile,$qq,$withdrawal_cipher) {
        $res = Username::name('username')
        ->bind(['username'=>$username,'bankren'=>$account_holder,'bankname'=>$account_bank,'bankno'=>$account_number,'banksf'=>$province,'banksq'=>$city,'mobile'=>$mobile,'qq'=>$qq,'ejmm'=>$withdrawal_cipher])
        ->where('username',':username')
        ->update(['bankren'=>':bankren','bankname'=>':bankname','bankno'=>':bankno','banksf'=>':banksf','banksq'=>':banksq','mobile'=>':mobile','qq'=>':qq','ejmm'=>':ejmm']);
        return $res;
    }
    //清除用户登录秘钥
    public function updateLoginKey($id) {
        $res = Username::name('username')
        ->bind(['id'=>$id])
        ->where('id',':id')
        ->data(array('login_key'=>''))
        ->update();
        return $res;
    }
    //记录违规记录过多时锁定账号
    public function LockAccount($user) {
        $res = Username::name('username')
        ->bind(['username'=>$user])
        ->where('username',':username')
        ->data(['open'=>'1','login_key'=>'0'])
        ->update();
        return $res;
    }

}
